package com.fdq.bigevent.controller;

import com.fdq.bigevent.anno.State;
import com.fdq.bigevent.pojo.Article;
import com.fdq.bigevent.pojo.PageBean;
import com.fdq.bigevent.pojo.Result;
import com.fdq.bigevent.service.ArticleService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Validated
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result addArticle(@RequestBody @Validated Article article){
        return articleService.addArticle(article);
    }

    @GetMapping
    public Result<PageBean> getArticle(Integer pageNum, Integer pageSize,
                                       @RequestParam(required=false,defaultValue = "0") Integer categoryId,
                                       @RequestParam(required = false)  String state)
    {
        return articleService.getArticle(pageNum,pageSize,categoryId,state);
    }

    @GetMapping("/detail")
    public Result<Article> getArticleById(Integer id){
        return articleService.getArticleById(id);
    }

    @PutMapping
    public Result updateArticle(@RequestBody @Validated Article article){
        return articleService.updateArticle(article);
    }

    @DeleteMapping
    public Result deleteArticle(@NotNull Integer id){
        return articleService.deleteArticle(id);
    }
}
